//
//  StatusRetweetedCell.swift
//  Weibo8023
//
//  Created by styshy on 15/12/13.
//  Copyright © 2015年 sz. All rights reserved.
//

import UIKit
import FFLabel

class StatusRetweetedCell: StatusCell {
   override var viewModel:StatusViewModel?{
        didSet{
            // 设置数据
            let text = viewModel?.retweetedText ?? ""
            retweetedLabel.attributedText = EmoticonManager.sharedManager.emoticonText(text, font: retweetedLabel.font)
            
            
            pictureView.snp_updateConstraints { (make) -> Void in
                
                // 设置判断
                let offset = viewModel?.thumbnailUrls?.count > 0 ? StatusCellMargin : 0
                
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
                
            }
        }
    }
    
    // 背景按钮
    private lazy var backButton:UIButton = {
        let backBtn = UIButton()
        backBtn.backgroundColor = UIColor(white: 0.5, alpha: 1.0)
        
        return backBtn
    }()
    
    // 转发标签
    private lazy var retweetedLabel:FFLabel = {
        let label = FFLabel(title: "来大圣归来大圣归来",
            fontSize: 14,
            color: UIColor.darkGrayColor(),
            screenInset: StatusCellMargin)
        return label
    }()
}

extension StatusRetweetedCell{
    override func setupUI() {
        super.setupUI()
        
        // 1. 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        
        // 2. 自动布局
        // 1> 背景按钮
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
        }
        
        // 2> 转发标签
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
        // 3> 配图视图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        retweetedLabel.labelDelegate = self
    }

}
